package org.csu.mypetstore.persistence;

//this is completed
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.csu.mypetstore.domain.Item;
import org.csu.mypetstore.domain.LatestProduct;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;
@Repository
public interface ItemMapper extends BaseMapper<Item> {
    @Update("UPDATE INVENTORY SET QTY = QTY - #{increment} WHERE ITEMID = #{itemId};")
    void updateInventoryQuantity(Map<String, Object> param);

    @Select("SELECT QTY AS QUANTITY FROM INVENTORY WHERE ITEMID =  #{itemId};")
    int getInventoryQuantity(String itemId);

    @Select("SELECT * FROM item WHERE productid = #{productId};")
    List<Item> getItemListByProduct(String productId);

    @Select("SELECT  * FROM item WHERE itemid = #{itemId};")
    Item getItem(String itemId);
    //新上架的商品在主界面展示，同时在在后台增加增删改查的功能
    void insertLatestproduct(LatestProduct latestProduct);
    @Select("SELECT * FROM latestpruduct;")
    List<LatestProduct> selcetlatestproduct();
    @Delete("DELETE FROM latestpruduct WHERE itemid=#{itemid};")
    void deletelatestproduct(String itemid);
    void updateLatestproduct(LatestProduct latestProduct);
    @Select("SELECT itemId,productId,listprice AS listPrice,unitcost,supplier,status,attribute1 FROM item;")
    List<Item> getallItem();
    @Delete("DELETE  FROM item WHERE itemId=#{ItemId};")
    void deleteItem(String ItemId);
    @Insert("INSERT INTO item values (#{itemId},#{productId},#{listPrice},#{unitcost},#{supplier},#{status},#{attribute1},#{attribute2},#{attribute3},#{attribute4},#{attribute5});")
    void inserItem(Item item);
    @Select("SELECT itemId,productId,listprice AS listPrice,unitcost,supplier,status,attribute1 FROM item WHERE itemId LIKE #{keyword};")
    List<Item> searchItem(String keyword);
    @Insert("INSERT INTO inventory VALUES (#{itemId},#{quantity});")
    void insertQuantity(Item item);
    @Delete("DELETE FROM inventory WHERE itemid = #{ItemId};")
    void deletequantity(String ItemId);
    @Update("UPDATE item SET itemId = #{itemId}, productId = #{productId},listprice = #{listPrice},unitcost=#{unitcost},supplier = #{supplier},status = #{status},attribute1=#{attribute1},\n" +
            "        attribute2 = #{attribute2},attribute3 = #{attribute3},attribute4=#{attribute4},attribute5=#{attribute5} WHERE itemId = #{itemId};")
    void updateItem(Item item);
    @Update("UPDATE inventory SET qty = #{quantity} WHERE itemid = #{itemId};")
    void updateQuantity(Item item);
    //综合方法
    @Select("SELECT * FROM latestpruduct WHERE itemid=#{itemid};")
    Item isExistitem(String itemid);
    void updatelatestproduct(Item item);
    @Insert("INSERT INTO latestpruduct values (#{itemid},#{descn},#{listprice});")
    void insertLatestProduct(LatestProduct latestProduct);
    @Delete("DELETE FROM instock WHERE itemId=#{itemId};")
    void deleteinstock(String itemId);
    @Update("UPDATE instock SET isinstock = #{instock} WHERE itemId = #{itemId} ;")
    void updateinstock(@Param("itemId") String itemId,@Param("instock") String instock);
    @Insert("INSERT INTO instock VALUES (#{itemId},#{instock});")
    void insertinstock(Item item);
    @Select("SELECT isinstock FROM instock WHERE itemId=#{itemId};")
    String selectinstock(String itemId);

}
